#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

void Order(vector<int>& data)
{
	int count = data.size();

	for(int i=0; i<count; i++)
	{
		for(int j=0; j<count-i-1; j++)
		{
			if(data[j] > data[j+1])
			{
				int temp = data[j];
				data[j] = data[j+1];
				data[j+1] = temp;
			}
		}
	}
}

int main(void)
{
	vector<int> data;

	ifstream in("data.txt");
	if(!in)
	{
		cout << "failed to open data.txt" << endl;
		return 1;
	}
	int temp;
	/*
	while(!in.eof()) // error, result in last data read twice !
	{
		in >> temp;
		cout << temp << " ";
		data.push_back(temp);
	}
	*/
	while(in >> temp)
	{
		data.push_back(temp);
	}
	in.close();

	Order(data);

	ofstream out("data_sorted.txt");
	if(!out)
	{
		cout << "failed to open data_sorted.txt" << endl;
		return 1;
	}
	for(int i=0; i<data.size(); i++)
	{
		out << data[i] << " ";
	}
	out.close();

	return 0;
}
